package main

import "fmt"

func findJudge(n int, trust [][]int) int {
	var from []int = make([]int, n+1)
	var to []int = make([]int, n+1)

	for _, arr := range trust {
		from[arr[0]]++
		to[arr[1]]++
	}

	for i := 1; i <= n; i++ {
		if to[i] == n-1 && from[i] == 0 {
			return i
		}
	}
	return -1
}

func main() {
	arr1 := [][]int{{1, 3}, {2, 3}}
	arr2 := [][]int{{1, 2}, {2, 3}}
	arr3 := [][]int{{1, 3}, {2, 3}, {3, 1}}
	fmt.Println(findJudge(3, arr1))
	fmt.Println(findJudge(3, arr2))
	fmt.Println(findJudge(3, arr3))

}
